package oj;

import java.util.ArrayList;
import java.util.List;
//DFS算法
public class Num257 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> paths=new ArrayList<String>();
        help(root,"",paths);
        return paths;
        }

    public void help(TreeNode root,String path,List<String> paths) {
        if (root != null) {
            StringBuilder sb=new StringBuilder(path);
            sb.append(Integer.toString(root.val));

        if (root.left == null && root.right == null) {
            paths.add(sb.toString());
        }else{
            sb.append("->");
            help(root.left,  sb.toString(),paths );
            help(root.right,sb.toString(),paths);
            }
        }
    }
}
